package org.huangrui.juc.day03;

import java.util.concurrent.CountDownLatch;

/**
 * long --> 8个字节
 * @author hr
 * @createTime 2022-04-05 05:54
 */
public class T02_CacheLinePadding_Deprecated {
    private static long COUNT = 1_0000_0000L;
    private static class T{
        private volatile long p1,p2,p3,p4,p5,p6,p7;
        private volatile long x = 0;
        private volatile long p8,p9,p10,p11,p12,p13,p14;
    }
    private static T[] arr = new T[2];
    static {
        arr[0] = new T();
        arr[1] = new T();
    }
    public static void main(String[] args) throws InterruptedException {
        CountDownLatch latch = new CountDownLatch(2);
        Thread t1 = new Thread(() -> {
            for (int i = 0; i < COUNT; i++) {
                arr[0].x = i;
            }
            latch.countDown();
        }, "t1");
        Thread t2 = new Thread(() -> {
            for (int i = 0; i < COUNT; i++) {
                arr[1].x = i;
            }
            latch.countDown();
        }, "t2");
        long start = System.nanoTime();
        t1.start();
        t2.start();
        latch.await();
        System.out.println((System.nanoTime()-start)/100_000);
    }
}
